﻿using System;
namespace Producers.Karis.Xtee.Riik.Ee.Producer.Karis {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="kvk_isikud_paring", Namespace="http://producers.karis.xtee.riik.ee/producer/karis", Target=typeof(KvkIsikudParing))]
    public class KvkIsikudParingSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IKvkIsikudParing clazz;
        
        public KvkIsikudParingSerializer(IKvkIsikudParing clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("synd_alates");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "date");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdDate(((System.DateTime)(clazz.SyndAlates))).ToString());
            Writer.WriteEndElement();
            Writer.WriteStartElement("synd_kuni");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "date");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdDate(((System.DateTime)(clazz.SyndKuni))).ToString());
            Writer.WriteEndElement();
            Writer.WriteStartElement("kar_liik");
            if (clazz.KarLiik!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.KarLiik))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : KarLiik");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("sugu");
            if (clazz.Sugu!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Sugu))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Sugu");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("kodakondsus");
            if (clazz.Kodakondsus!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Kodakondsus))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Kodakondsus");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
        START:
            if ((Reader.LocalName == "synd_alates")) {
                goto synd_alates;
            }
            else {
                if ((Reader.LocalName == "synd_kuni")) {
                    goto synd_kuni;
                }
                else {
                    if ((Reader.LocalName == "kar_liik")) {
                        goto kar_liik;
                    }
                    else {
                        if ((Reader.LocalName == "sugu")) {
                            goto sugu;
                        }
                        else {
                            if ((Reader.LocalName == "kodakondsus")) {
                                goto kodakondsus;
                            }
                            else {
                                return;
                            }
                        }
                    }
                }
            }
        synd_alates:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>kvk_isikud_paring>synd_alates");
            }
            clazz.SyndAlates = new global::Xtee.Core.Schema.XsdDate(Reader.ReadElementString("synd_alates")).Value;
            goto START;
        synd_kuni:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>kvk_isikud_paring>synd_kuni");
            }
            clazz.SyndKuni = new global::Xtee.Core.Schema.XsdDate(Reader.ReadElementString("synd_kuni")).Value;
            goto START;
        kar_liik:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>kvk_isikud_paring>kar_liik");
            }
            clazz.KarLiik = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("kar_liik")).Value;
            goto START;
        sugu:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>kvk_isikud_paring>sugu");
            }
            clazz.Sugu = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("sugu")).Value;
            goto START;
        kodakondsus:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>kvk_isikud_paring>kodakondsus");
            }
            clazz.Kodakondsus = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("kodakondsus")).Value;
            goto START;
        }
    }
}
